<?php
my_component_load('testing' , false);
my_component_load('paging' , false);
my_component_load('alamat' , false);
my_component_load('karyawan');
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$id = isset( $_GET['id'] ) ? $_GET['id']:  0;

$modulname_karyawan = "Personalia _BN_ Data Karyawan _BN_ Data Pribadi";
if($_SERVER['REQUEST_METHOD'] == "POST" ):
	switch($task){
		case "create_calon":
			form_submit_calon_create($id);
			my_direct('index.php?com=karyawan&task=calon');
		break;
		
		case   "create" :
		case   "edit" :
			if(! is_admin())fatal_error('Akses ditolak!!!');
			$validate = form_submit_validate();
			if($validate){
				$pagename = (($id > 0 ) ? "Edit" :"Tambah" )." data karyawan";
				$content = message_multi_error($validate );
				$content .= form_create($id);
			}else{
				$kid = form_submit($id);
				my_direct('index.php?com=karyawan');
			}
			/*
			if($id == 0){ 
				my_direct('index.php?com=karyawan&task=detail_entry_karyawan&id='	.	$kid);
			}else{
				my_direct('index.php?com=karyawan&task=detail&id='	.	$id);
			}*/
		break;
		case "ganti_photo_page":  
			$karyawan =my_get_data_by_id('karyawan','karyawan_id',$id); 
			$del = delete_photo($karyawan['biodata_id']);
			$upload = move_uploaded_photo( $_FILES['photo']  , $karyawan['biodata_id']); 
			my_direct($_SERVER['HTTP_REFERER']);
		break;
	}

else: 	
	if($task == "create"){
		if(! is_admin())fatal_error('Akses ditolak!!!');
		$pagename = $modulname_karyawan." _BN_ Tambah Data";
		$content = form_create();
	}elseif($task == "set_opsi"){
	 
			$q="UPDATE opsi_seting set value='{$_GET['val']}' WHERE name='karyawan_only'";
			 
			my_query($q);
			my_direct($_SERVER['HTTP_REFERER']);
		 
	}elseif($task == "edit"){
		if(! is_admin())fatal_error('Akses ditolak!!!');
		$pagename =$modulname_karyawan." _BN_ Ubah Data";
		$content = form_create($id);
	}elseif($task == "detail_entry_karyawan"){
		$content = detail_entry($id);
	}elseif($task == "detail"){
		if(is_calon($id)){
			my_direct('index.php?com=karyawan&task=detail_calon&id='.$id);
		}
		load_facebox_script();
		$karyawan = loaddata_karyawan($id);
		$pagename = $modulname_karyawan." _BN_ Detail ";
		$content = form_detail($id);
	}elseif($task == "detail_calon"){
		load_facebox_script();
		$karyawan = loaddata_karyawan($id);
		$pagename = "Detail data pelamar ".$karyawan['nama'];
		$content = form_detail_pelamar($id);
	}elseif($task == "ganti_photo_page"){ 
		$content  = ganti_photo( $id );
		generate_my_web($content,"","plain.php");
		exit;		
	}elseif($task == 'delete'){	
		delete_karyawan($id);
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == 'ganti_photo'){	
		if(! is_admin())fatal_error_page('Akses ditolak!!!' ,'plain.php');
		$title=  "Ganti photo karyawan" ;
		facebox_page('index.php?com=karyawan&task=ganti_photo_page&id='.$id  , $title , 250	); 
	}elseif($task =='delete_photo'){
		$karyawan =my_get_data_by_id('karyawan','karyawan_id',$id);
		delete_photo($karyawan['biodata_id']);
		my_direct($_SERVER['HTTP_REFERER']);
	}elseif($task == 'excel_daftar_biodata'){ 
		header("Content-Type: application/xls");
		header("Content-Disposition: attachment;filename=data_master_biodata.xls");
		echo export_to_excel_biodata();
		exit;
	}elseif($task == 'create_calon'){
		$pagename = ($id ==0) ? "Ubah data calon karyawan":"Tambah calon karyawan";
		$content = form_calon_create($id);
	}elseif($task == 'calon'){
		$pagename = "Penempatan _BN_ Calon Karyawan _BN_ Calon Karyawan";
		load_facebox_script();
		$content = report_calon_karyawan();
	}else{
		$pagename = $modulname_karyawan;
		load_facebox_script();
		$content = report_karyawan();
	}
endif; 
generate_my_web($content, $pagename  );
?>